package com.shiliao.app.activity.index.presenter;

import com.shiliao.app.activity.index.service.IManinService;
import com.shiliao.app.activity.index.service.impl.MainImpl;
import com.shiliao.app.activity.index.view.MainView;
import com.shiliao.app.update.UpdateEntity;
import com.shiliao.app.utils.YMServerUtil;
import com.yimei.framework.mvp.presenter.IBasePresenter;
import com.yimei.framework.network.ICallBack;
import com.yimei.framework.util.LogUtil;
import com.yimei.framework.util.ParseHelper;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by yinzhiqiang on 2017/12/18.
 */

public class MainPresenter extends IBasePresenter {
    private MainView mainView;
    private IManinService iManinService;

    public MainPresenter(MainView mainView) {
        this.mainView = mainView;
        iManinService = new MainImpl();
        setService(iManinService);
    }

    public void requestUpdate(String version, String userId) {
        Map param = new HashMap();
        param.put("device_type", "android");
        param.put("app_version", version);
        param.put("user_id", userId);
        LogUtil.e("yzq", "更新：" + YMServerUtil.ACTION_UPDATE + version);
        iManinService.request(YMServerUtil.ACTION_UPDATE, param, new ICallBack() {
            @Override
            public void onSuccess(int statusCode, Object result) {
                LogUtil.e("yzq", "更新：" + result);
                UpdateEntity updateEntity = ParseHelper.getModel(result.toString(), "data", UpdateEntity.class);
                if (mainView != null) {
                    mainView.showDownloadDialog(updateEntity);
                }
            }

            @Override
            public void onFail(int statusCode, Object result) {
                LogUtil.e("yzq", "更新：" + result);
            }
        });
    }

//    public void requestReminder(String userId) {
//        Map map = new HashMap();
//        map.put("user_id", userId);
//        LogUtil.e("yzq", userId);
//        iManinService.requestReminder(YMServerUtil.ACTION_NOTICE_CONTEN, map, new ICallBack() {
//            @Override
//            public void onSuccess(int statusCode, Object result) {
////                List<AddRemindEntity> list= ParseHelper.getModelList(result.toString(),"reminder_array", AddRemindEntity.class);
////                if (list.size()>0){
////                    LogUtil.e("yzq","发送通知");
//                String isNotice = ParseHelper.getString(result.toString(), "has_notice");
//                String noticeTitle = ParseHelper.getString(result.toString(), "notice");
//                mainView.sendNotice(isNotice, noticeTitle);
////                }
//                LogUtil.e("yzq", result + "=====");
//            }
//
//            @Override
//            public void onFail(int statusCode, Object result) {
//
//            }
//        });
//    }
}
